﻿/***************************************************************************
 *   Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de>              *
 *   Copyright (c) 2011 Werner Mayer <wmayer[at]users.sourceforge.net>     *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 of the License, or (at your option) any later version.      *
 *                                                                         *
 *   This library  is distributed in the hope that it will be useful,      *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/


#include "pch.h"
#include <cassert>
#include <atomic>


#include "Transactions.h"

#include "Base/Console.h"
#include "Property.h"


FC_LOG_LEVEL_INIT("App", true, true)

using namespace App;
using namespace std;

TYPESYSTEM_SOURCE(App::Transaction, Base::BaseClass)

//**************************************************************************
// Construction/Destruction

Transaction::Transaction(int id) {}

/**
 * A destructor.
 * A more elaborate description of the destructor.
 */
Transaction::~Transaction() {}

static std::atomic<int> _TransactionID;

int Transaction::getNewID() {
    int id = ++_TransactionID;
    if (id)
        return id;
    // wrap around? really?
    return ++_TransactionID;
}

int Transaction::getLastID() {
    return _TransactionID;
}

unsigned int Transaction::getMemSize(void) const {
    return 0;
}

void Transaction::Save ( ) const
{
    assert(0);
}

void Transaction::Restore( )
{
    assert(0);
}
int Transaction::getID(void) const {
    return transID;
}

bool Transaction::isEmpty() const { return false; }

bool Transaction::hasObject(const TransactionalObject* Obj) const { return false; }

void Transaction::addOrRemoveProperty(TransactionalObject* Obj,
                                      const Property* pcProp, bool add) {}

//**************************************************************************
// separator for other implementation aspects


void Transaction::apply(Document& Doc, bool forward) {}

void Transaction::addObjectNew(TransactionalObject* Obj) {}

void Transaction::addObjectDel(const TransactionalObject* Obj) {}

void Transaction::addObjectChange(const TransactionalObject* Obj, const Property* Prop) {}


//**************************************************************************
//**************************************************************************
// TransactionObject
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


//**************************************************************************
// Construction/Destruction
TYPESYSTEM_SOURCE(TransactionObject, Base::BaseClass)

/**
 * A constructor.
 * A more elaborate description of the constructor.
 */
TransactionObject::TransactionObject() {}

/**
 * A destructor.
 * A more elaborate description of the destructor.
 */
TransactionObject::~TransactionObject() {}

void TransactionObject::applyDel(Document& /*Doc*/, TransactionalObject* /*pcObj*/) {}

void TransactionObject::applyNew(Document& /*Doc*/, TransactionalObject* /*pcObj*/) {}

void TransactionObject::applyChn(Document& /*Doc*/, TransactionalObject* pcObj, bool /* Forward */) {}

void TransactionObject::setProperty(const Property* pcProp) {}

void TransactionObject::addOrRemoveProperty(const Property* pcProp, bool add) {}

unsigned int TransactionObject::getMemSize(void) const {
    return 0;
}
void TransactionObject::Save () const
{
    assert(0);
}

void TransactionObject::Restore()
{
    assert(0);
}

//**************************************************************************
//**************************************************************************
// TransactionDocumentObject
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

TYPESYSTEM_SOURCE(TransactionDocumentObject, Base::BaseClass)

//**************************************************************************
// Construction/Destruction

/**
 * A constructor.
 * A more elaborate description of the constructor.
 */
TransactionDocumentObject::TransactionDocumentObject() {}

/**
 * A destructor.
 * A more elaborate description of the destructor.
 */
TransactionDocumentObject::~TransactionDocumentObject() {}

void TransactionDocumentObject::applyDel(Document& Doc, TransactionalObject* pcObj) {}

void TransactionDocumentObject::applyNew(Document& Doc, TransactionalObject* pcObj) {}

//**************************************************************************
//**************************************************************************
// TransactionFactory
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

TransactionFactory* TransactionFactory::self = nullptr;

TransactionFactory& TransactionFactory::instance() {
    if (self == nullptr)
        self = new TransactionFactory;
    return *self;
}

void TransactionFactory::destruct() {
    delete self;
    self = nullptr;
}


/**
 * Creates a transaction object for the given type id.
 */
TransactionObject* TransactionFactory::createTransaction(const Base::Type& type) const { return nullptr; }
